import { Component, OnInit } from '@angular/core';
import { SimpleTableColumn } from '@delon/abc';
import { HttpClient } from '@angular/common/http';


@Component({
    selector: 'app-dept-list',
    templateUrl: './dept-list.component.html',
})

export class DeptListComponent implements OnInit {
    //url = `api/sys/dept/list`;
    _dataSet: any[] = [];
    //total: number;
    columns: SimpleTableColumn[] = [
        { title: '编号', index: 'id' },
        { title: '用户名', index: 'name' },
        {
            title: '操作',
            buttons: [
                {
                    text: '删除', type: 'del', click: (record: any) => {

                    }
                }
            ]
        }
    ];

    constructor(private httpClient: HttpClient) { }

    ngOnInit() {
        this.getData();
    }

    getData() {
        // this.httpClient.get('api/sys/dept/list').subscribe((res: any) => {
        //     console.log(res.data);
        //     //this._dataSet = res.data;
        //     this._dataSet=Array(5).fill({}).map((item: any, idx: number) => {
        //         return {
        //             id: idx + 1,
        //             name: `name ${idx + 1}`
        //         };
        //     })
        //     this.total=2;
        // });

        new Promise<any>((resolve, reject) => {
            this.httpClient.get('api/sys/dept/list').subscribe((res: any) => {
                resolve(res);
            });
        })
            .then(response => {
                this._dataSet = response.data;
               // this.total = 2;
            });
    }

}